//- 先去这个pug文件中找
extends ../commons/commons.pug

block append pageStyle
	link(href="${relativePath}/static/css/shopping/tjOrder.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/iconfont.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/fileUpload.css" rel="stylesheet" type="text/css")

block content
	//- 提交订单内容
	div.placeOrderCon.layout
		//- logo部分
		div.submitHeader
			div.logo.fl
				img(src="${relativePath}/static/imgs/shopin.png")

			//- 进度条
			div.orderProcess.fr
				div.processBox
					span.progress1.current
						span.num 1
						br
						span.progressMsg 提交订单
					span.progress1.progress2
						span.num 2
						br
						span.progressMsg 商家接单
					span.progress1.progress3
						span.num 3
						br
						span.progressMsg 支付
					span.progress1.progress4
						span.num 4
						br
						span.progressMsg 完成
		//- 收货地址
		div.receAddress
			h3 选择收货地址

			//- 所有地址列表
			div.addressBox
				ul.addressList
					//- li.current
					//- 	p.name 收货人
					//- 	div.addressTxt
					//- 		p.address 河南省郑州市经开区南三环经开25大街索凌电气
					//- 		p.phone 13332112321

					//- li
					//- 	p.name 收货人
					//- 	div.addressTxt
					//- 		p.address 河南省郑州市经开区南三环经开25大街索凌电气
					//- 		p.phone 13332112321
				p.clickBtn
					a.displayAll(href="javascript:;") 显示全部地址 >
					a.new(href="javascript:;") 使用新地址

			h3 确认商品信息
			//- 确认商品列表
			div.goodsBox
				div.goodsTitle
					ul
						li.spName 商品名称
						li.spMsg 商品信息
						li.unitPrice 单价
						li.number 数量
						li.count 总价
				div.buyList.buyList_c
					div.buyName.fl
						div.imgBox.fl
							img(src="")
						div.txtBox.fl
							p 
					//- 商品信息
					ul.msgCon.fl
						//li 材质：金属拉丝
					//- 单价
					div.djBox.fl
						span.real
					//- 数量
					div.numberBox.fl 1
					
					//- 总价
					div.allCount.fl.allCount_1
			div.deverlyDate
				span.zdsj
					| 指定商家：
					i 河南省标识汇有限公司	
			//- 提交订单		
			div.submitBtn
				div.allMoney.fr
					span 共有1件商品
					span.allCount.allCount_2
						| 共计：
						i ￥
						em 
					span#sub.tjBtn.fr 加入购物车 >

	//- 收货地址模板
	script#address(type="text/html")
		| <li {{if acqu == 1}}class="current"{{/if}} id="{{id}}">
		| 	<p class="name" name="{{accept_name}}">
		|	{{accept_name}}
		|		<a class="fr delete">删除</a>
		|		<a class="fr modify">修改</a>
		|	</p>
		| 	<div class="addressTxt">
		| 		<p class="address" address="{{province_name}}{{city_name}}{{address}}{{area_name}}"> 	{{province_name}}{{city_name}}{{address}}{{area_name}}</p>
		| 		<p class="phone" call="{{mobile}}"> {{mobile}}</p>
		| 	</div>
		| </li>

	

block pageScript
	script(type="text/javascript" src="${relativePath}/static/js/libs/iconfont.js")
	script(type="text/javascript" src="${relativePath}/static/js/libs/fileUpload.js")

	script.
		//- 规格拼接
		var spec = {};
		var nameArr = decodeURI($.cookie("specidTxtArr")).split(",");
		var valueArr = decodeURI($.cookie("specidTitleArr")).split(",");
		for(var i=0; i<nameArr.length; i++) {
			spec[nameArr[i]] = valueArr[i];
		}

		$.each( spec, function(i, n){
		  	var LiEle = "<li>"+i+':'+n+"</li>";
		  	$(".msgCon").append(LiEle);
		});

		//console.log(spec);
		$(function(){
			//- 选择收货日期
			$('#timeOne').fdatepicker({
				format: 'yyyy-mm-dd',
				onRender: function (date) {
					var nowTemp = new Date();
					var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
					return date.valueOf() < now.valueOf() ? 'disabled' : '';
				}
			});

			//- 点击收货地址
			$(".addressList").on("click","li",function(){
				$(this).addClass("current").siblings().removeClass("current");
			});
			//- 收货地址列表
			$.getJSON(shopIp+"/Address/lst?callback=?",{
				userToken:token,
				os:"web",
			},function(data){
				if(data.data.length > 4){
					$(".displayAll").show();
				}
				if(data.status == "200" && data.data.length>0){
					for(var i=0;i<data.data.length;i++) {
						var addressHtml = template("address",data.data[i]);
						$(".addressList").append(addressHtml);
					}
				}else{
				$(".addressList").append('<a class="addAddress addAddresshref" href="../personCenter/receveAddress.html" target="_blank">'+"请添加收货地址"+'</a><p class="protxt">请点击去个人中心完善收货信息，添加完之后请刷新本窗口。</p>');
					$(".displayAll").hide();
					$(".clickBtn .new").hide();
				}
			})
			//- 确认商品信息
			//console.log(thisRequest.price);
			//var sizeArr = thisRequest.size.split("x");
			$(".imgBox img").attr("src",thisRequest.src);
			$(".txtBox p").html(decodeURI(thisRequest.title));
			$(".real").html(thisRequest.price);
			$(".numberBox").html(thisRequest.number);
			$(".zdsj i").html(decodeURI($.cookie("ghsName")));
			$(".allCount_1").html((thisRequest.number)*(thisRequest.price));
			$(".allCount_2 em").text((thisRequest.number)*(thisRequest.price));
			//- 规格信息

			//- 点击提交
			//console.log(thisRequest.sku_id);
			$("#sub").click(function() {
				var name = $("li.current .name").attr("name");
				var call = $("li.current .phone").attr("call");
				var address = $("li.current .address").attr("address");
				$.post(shopIp+"/My/addCart",{
					userToken:token,
					goods_num:$(".numberBox").html(),
					order_amount:$(".allCount_1").html(),
					goods_category_id:thisRequest.id,
					sku_id:thisRequest.sku_id,
					seller_id:thisRequest.companies,
					reciver_name:name,
					reciver_mobile:call,
					reciver_address:address
				},function(data){
					if(data.status == "200") {
						var orderId = data.data.order_id;
						$(".gwCar i").html(data.data.cart_number);
						window.location.href="../personCenter/shopCar.html";
					}else{
						layer.msg(data.msg);
					}
					
				})
			});
			//- 点击修改地址
			$(".addressList").on("click",".modify",function() {
				window.location.href="../personCenter/receveAddress.html";
			})
			//- 点击删除地址
			$(".addressList").on("click",".delete",function() {
				var $this = $(this);
				layer.confirm('您确定删除此收货地址？', {
					btn: ['确定','取消'],//按钮
					title:"删除收货地址"
				}, function(){
					$.post(shopIp+"/Address/delAccept",{
						userToken:token,
						id:$this.closest("li").attr("id"),
					},function(data) {
						//console.log(data.msg);
						if(data.status == "200") {
							layer.msg(data.msg, {icon: 1});
							$this.closest("li").remove();
							setTimeout(function() {
								location.reload();
							},1000);
						} else{
							layer.msg(data.msg);
						}
					})
				}, function(){
					//layer.msg('已取消');
				});
			})

			//- 点击查看全部地址
			$(".displayAll").click(function() {
				if($(this).text() == "显示全部地址 >") {
					$(".addressList").css("height","auto");
					$(this).html("隐藏收货地址 >");
				} else{
					$(".addressList").css("height","165px");
					$(this).html("显示全部地址 >");
				}
				
			})
		});


		